#include <bits/stdc++.h>
// 2025/02/01
// tag: 
// Author: Zhang Muen
using namespace std;

const int maxn = 1000005;
int64_t n, m, diff[maxn], d[maxn], s[maxn], t[maxn], r[maxn];

bool check(int day){
    memset(diff, 0, sizeof(diff));
    for (int i = 1; i <= day; i++){
        diff[s[i]] += d[i];
        diff[t[i] + 1] -= d[i];
    }
    for (int i = 1; i <= n; i++){
        diff[i] += diff[i - 1];
        if (diff[i] > r[i])
            return false;
    }
    return true;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        cin >> r[i];
    for (int i = 1; i <= m; i++)
        cin >> d[i] >> s[i] >> t[i];
    int l = 1, r = n;
    while (l <= r){
        int mid = (l + r) >> 1;
        if (check(mid))
            l = mid + 1;
        else
            r = mid - 1;
    }
    if (r == n)
        cout << 0 << endl;
    else    
        cout << -1 << endl << r + 1 << endl;
    return 0;
}